/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConnectionBox.java
 *
 * Created on 23 févr. 2010, 11:35:47
 */
package client;

import org.jdesktop.application.Action;

/**
 *
 * @author berthise
 */
public class ConnectionBox extends javax.swing.JDialog {

    /** Creates new form ConnectionBox */
    public ConnectionBox(ChatView client, java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.client = client;
        getRootPane().setDefaultButton(cancelButton);
        numPortSpinner.setValue(10009);
    }
    private ChatView client = null;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nickNameLabel = new javax.swing.JLabel();
        serverLabel = new javax.swing.JLabel();
        numPortLabel = new javax.swing.JLabel();
        nickNameTextField = new javax.swing.JTextField();
        serverTextField = new javax.swing.JTextField();
        numPortSpinner = new javax.swing.JSpinner();
        infoLabel = new javax.swing.JLabel();
        connectionButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(client.ChatApp.class).getContext().getResourceMap(ConnectionBox.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        nickNameLabel.setText(resourceMap.getString("nickNameLabel.text")); // NOI18N
        nickNameLabel.setName("nickNameLabel"); // NOI18N

        serverLabel.setText(resourceMap.getString("serverLabel.text")); // NOI18N
        serverLabel.setName("serverLabel"); // NOI18N

        numPortLabel.setText(resourceMap.getString("numPortLabel.text")); // NOI18N
        numPortLabel.setName("numPortLabel"); // NOI18N

        nickNameTextField.setText(resourceMap.getString("nickNameTextField.text")); // NOI18N
        nickNameTextField.setName("nickNameTextField"); // NOI18N

        serverTextField.setText(resourceMap.getString("serverTextField.text")); // NOI18N
        serverTextField.setName("serverTextField"); // NOI18N

        numPortSpinner.setName("numPortSpinner"); // NOI18N

        infoLabel.setText(resourceMap.getString("infoLabel.text")); // NOI18N
        infoLabel.setName("infoLabel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(client.ChatApp.class).getContext().getActionMap(ConnectionBox.class, this);
        connectionButton.setAction(actionMap.get("setConnection")); // NOI18N
        connectionButton.setText(resourceMap.getString("connectionButton.text")); // NOI18N
        connectionButton.setName("connectionButton"); // NOI18N

        cancelButton.setAction(actionMap.get("closeConnectionBox")); // NOI18N
        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(serverLabel)
                            .addComponent(nickNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(connectionButton)
                            .addComponent(numPortLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(numPortSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(serverTextField)
                                .addComponent(nickNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(cancelButton)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(infoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(infoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nickNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(nickNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(serverLabel)
                    .addComponent(serverTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numPortSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numPortLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(connectionButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void closeConnectionBox() {
        dispose();
    }

    @Action
    public void setConnection() {
        String login = new String(nickNameTextField.getText());
        String serveur = new String(serverTextField.getText());
        int numPort = Integer.parseInt(numPortSpinner.getValue().toString());
        client.initConnection(login, serveur, numPort);
        dispose();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton connectionButton;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JLabel nickNameLabel;
    private javax.swing.JTextField nickNameTextField;
    private javax.swing.JLabel numPortLabel;
    private javax.swing.JSpinner numPortSpinner;
    private javax.swing.JLabel serverLabel;
    private javax.swing.JTextField serverTextField;
    // End of variables declaration//GEN-END:variables
}
